import React from 'react';
import {
	Route,
	Switch,
	Redirect
} from 'react-router-dom';
import Loadable from 'react-loadable';



const Loading = (props) => {
	if (props.error) {
		return <div className="loadable-load-page">Error! <button onClick={props.retry}>Retry</button></div>;
	} else if (props.pastDelay) {
		return <div className="loadable-load-page">Loading...</div>;
	} else {
		return null;
	}
};


const PageRoute = () => {
	return (
		<Switch>
			<Route exact path="/app/" component={
				Loadable({
					loader: () => import(/* webpackChunkName: "pages/dashboard" */ '@/view/pages/dashboard/dashboard'),
					loading: Loading,
					delay: 300,
				})
			} />
			{/* 用户 */}
			<Route exact path="/app/user" component={
				Loadable({
					loader: () => import(/* webpackChunkName: "pages/user" */ '@/view/pages/user/userlist'),
					loading: Loading,
					delay: 300,
				})
			} />
			<Route exact path="/app/user/adduser" component={
				Loadable({
					loader: () => import(/* webpackChunkName: "pages/user" */ '@/view/pages/user/adduser'),
					loading: Loading,
					delay: 300,
				})
			} />


			{/* 博文管理 */}
			<Route exact path="/app/article" component={
				Loadable({
					loader: () => import(/* webpackChunkName: "pages/article" */ '@/view/pages/article/article'),
					loading: Loading,
					delay: 300,
				})
			} />
			<Route exact path="/app/add-article" component={
				Loadable({
					loader: () => import(/* webpackChunkName: "pages/article" */ '@/view/pages/article/add-article'),
					loading: Loading,
					delay: 300,
				})
			} />
			<Route exact path="/app/article-detail" component={
				Loadable({
					loader: () => import(/* webpackChunkName: "pages/article" */ '@/view/pages/article/article-detail'),
					loading: Loading,
					delay: 300,
				})
			} />


			{/* 标签 */}
			<Route exact path="/app/tag" component={
				Loadable({
					loader: () => import(/* webpackChunkName: "pages/tag" */ '@/view/pages/tag/tag'),
					loading: Loading,
					delay: 300,
				})
			} />
			<Route exact path="/app/tag/addTag" component={
				Loadable({
					loader: () => import(/* webpackChunkName: "pages/tag" */ '@/view/pages/tag/addTag/'),
					loading: Loading,
					delay: 300,
				})
			} />

			{/* 分类管理 */}
			<Route exact path="/app/classify" component={
				Loadable({
					loader: () => import(/* webpackChunkName: "pages/classify" */ '@/view/pages/classify/classify'),
					loading: Loading,
					delay: 300,
				})
			} />
			<Route exact path="/app/classify/addClassify" component={
				Loadable({
					loader: () => import(/* webpackChunkName: "pages/classify" */ '@/view/pages/classify/addClassify'),
					loading: Loading,
					delay: 300,
				})
			} />

			<Route render={() => <Redirect to="/404" />} />
		</Switch>
	);
};
export default PageRoute;


